{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Determine the Winner of a Bowling Game"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isWinner"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #保龄球游戏的获胜者"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个下标从 <strong>0</strong> 开始的整数数组 <code>player1</code> 和 <code>player2</code> ，分别表示玩家 1 和玩家 2 击中的瓶数。</p>\n",
    "\n",
    "<p>保龄球比赛由 <code>n</code> 轮组成，每轮的瓶数恰好为 <code>10</code> 。</p>\n",
    "\n",
    "<p>假设玩家在第 <code>i</code> 轮中击中&nbsp;<code>x<sub>i</sub></code> 个瓶子。玩家第 <code>i</code> 轮的价值为：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>如果玩家在该轮的前两轮的任何一轮中击中了 <code>10</code> 个瓶子，则为 <code>2x<sub>i</sub></code> 。</li>\n",
    "\t<li>否则，为&nbsp;<code>x<sub>i</sub></code> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>玩家的得分是其 <code>n</code> 轮价值的总和。</p>\n",
    "\n",
    "<p>返回</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>如果玩家 1 的得分高于玩家 2 的得分，则为 <code>1</code> ；</li>\n",
    "\t<li>如果玩家 2 的得分高于玩家 1 的得分，则为 <code>2</code> ；</li>\n",
    "\t<li>如果平局，则为 <code>0</code> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>player1 = [4,10,7,9], player2 = [6,5,2,3]\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>player1 的得分是 4 + 10 + 2*7 + 2*9 = 46 。\n",
    "player2 的得分是 6 + 5 + 2 + 3 = 16 。\n",
    "player1 的得分高于 player2 的得分，所以 play1 在比赛中获胜，答案为 1 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>player1 = [3,5,7,6], player2 = [8,10,10,2]\n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：</strong>player1 的得分是 3 + 5 + 7 + 6 = 21 。\n",
    "player2 的得分是 8 + 10 + 2*10 + 2*2 = 42 。\n",
    "player2 的得分高于 player1 的得分，所以 play2 在比赛中获胜，答案为 2 。</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>player1 = [2,3], player2 = [4,1]\n",
    "<strong>输出：</strong>0\n",
    "<strong>解释：</strong>player1 的得分是 2 + 3 = 5 。\n",
    "player2 的得分是 4 + 1 = 5 。\n",
    "player1 的得分等于 player2 的得分，所以这一场比赛平局，答案为 0 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>n == player1.length == player2.length</code></li>\n",
    "\t<li><code>1 &lt;= n &lt;= 1000</code></li>\n",
    "\t<li><code>0 &lt;= player1[i], player2[i] &lt;= 10</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [determine-the-winner-of-a-bowling-game](https://leetcode.cn/problems/determine-the-winner-of-a-bowling-game/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [determine-the-winner-of-a-bowling-game](https://leetcode.cn/problems/determine-the-winner-of-a-bowling-game/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[4,10,7,9]\\n[6,5,2,3]', '[3,5,7,6]\\n[8,10,10,2]', '[2,3]\\n[4,1]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def calculate(list1):\n",
    "            if len(list1)==1:\n",
    "                return list1[0]\n",
    "            l1=list1[:]\n",
    "            for i in range(len(l1)-2):\n",
    "                if list1[i]==10:\n",
    "                    l1[i+1]=list1[i+1]*2\n",
    "                    l1[i+2]=list1[i+2]*2\n",
    "            if list1[-2]==10:\n",
    "                l1[-1]=list1[-1]*2\n",
    "            return sum(l1)\n",
    "        if calculate(player1)>calculate(player2):\n",
    "            return 1\n",
    "        elif calculate(player1)==calculate(player2):\n",
    "            return 0\n",
    "        else:\n",
    "            return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def f(x):\n",
    "            s=0\n",
    "            for i,k in enumerate(x):\n",
    "                if i==0:\n",
    "                    s+=k\n",
    "                elif i==1 and x[0]==10:\n",
    "                    s+=2*k\n",
    "                elif i==1 and x[0]!=10:\n",
    "                    s+=k\n",
    "                else:\n",
    "                    if x[i-1]==10 or x[i-2]==10:\n",
    "                        s+=2*k\n",
    "                    else:\n",
    "                        s+=k\n",
    "            return s\n",
    "        m,n=f(player1),f(player2)\n",
    "\n",
    "        if m>n:return 1\n",
    "        elif m<n:return 2\n",
    "        else:return 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def GetScore(a):\n",
    "    ans = 0\n",
    "    for i, x in enumerate(a):\n",
    "          if i > 0 and a[i-1] == 10 or i > 1 and a[i-2] == 10:\n",
    "              ans += x*2\n",
    "          else:\n",
    "              ans += x\n",
    "    return ans\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        s1 = GetScore(player1)\n",
    "        s2 = GetScore(player2)\n",
    "        return 1 if s1 > s2 else 2 if s1 < s2 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def score(s: list) -> int:\n",
    "            ans = 0\n",
    "            ten_idx = -1\n",
    "            for i, x in enumerate(s):\n",
    "                if ten_idx != -1 and i - ten_idx <= 2:\n",
    "                    ans += x * 2\n",
    "                else:\n",
    "                    ans += x\n",
    "                if x == 10:\n",
    "                    ten_idx = i \n",
    "            return ans\n",
    "\n",
    "        a, b = score(player1), score(player2)\n",
    "        if a > b: return 1\n",
    "        elif a < b: return 2\n",
    "        else: return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def gets(L):\n",
    "            s = 0\n",
    "            for i in range(len(L)):\n",
    "                s += L[i]\n",
    "                if i == 1:\n",
    "                    if L[0] == 10:\n",
    "                        s += L[i]\n",
    "                elif i > 1:\n",
    "                    if max(L[i-2:i]) == 10:\n",
    "                        s += L[i]\n",
    "            return s\n",
    "        s1, s2 = gets(player1), gets(player2)\n",
    "        if s1 == s2:\n",
    "            return 0\n",
    "        if s1 > s2:\n",
    "            return 1\n",
    "        return 2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def sumScore(player: List[int]) -> int:\n",
    "            score = 0\n",
    "            for i in range(len(player)):\n",
    "                if i ==  1:\n",
    "                    if player[0] == 10:\n",
    "                        score += player[1] * 2\n",
    "                        continue\n",
    "                if i >= 2:\n",
    "                    if player[i-1] == 10 or player[i-2] == 10:\n",
    "                        score += player[i] * 2\n",
    "                        continue\n",
    "                score += player[i]\n",
    "            return score\n",
    "        if sumScore(player1) < sumScore(player2):\n",
    "            return 2\n",
    "        elif sumScore(player1) > sumScore(player2):\n",
    "            return 1\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def calculate(player,score=0):\n",
    "            for i in range(len(player)):\n",
    "                if i==1 and player[i-1]==10:\n",
    "                    score+=2*player[i]\n",
    "                elif i-2 >=0 and 10 in player[i-2:i]:\n",
    "                    score+=2*player[i]\n",
    "                else:\n",
    "                    score+=player[i]\n",
    "            return score\n",
    "        if calculate(player1)>calculate(player2):\n",
    "            return 1\n",
    "        elif calculate(player1)==calculate(player2):\n",
    "            return 0\n",
    "        else:\n",
    "            return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def f(x):\n",
    "            s,t=0,0\n",
    "            for i,k in enumerate(x):\n",
    "                if t>0:\n",
    "                    s+=2*k\n",
    "                    t-=1\n",
    "                else:\n",
    "                    s+=k\n",
    "                if k==10:\n",
    "                    t=2  \n",
    "            return s\n",
    "        m,n=f(player1),f(player2)\n",
    "\n",
    "        if m>n:return 1\n",
    "        elif m<n:return 2\n",
    "        else:return 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def get_point(arr):\n",
    "    res = 0\n",
    "    for i in range(len(arr)):\n",
    "        if (i -1 >= 0 and arr[i-1] == 10) or (i-2>=0 and arr[i-2] == 10):\n",
    "            res += arr[i] * 2\n",
    "        else:\n",
    "            res += arr[i]\n",
    "    return res\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        a = get_point(player1)\n",
    "        b = get_point(player2)\n",
    "        if a > b:\n",
    "            return 1\n",
    "        elif a<b:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        if len(player1) > 1:\n",
    "            if player1[0] == 10:\n",
    "                p1 = 10 + (2 * player1[1])\n",
    "            else:\n",
    "                p1 = player1[0] + player1[1]\n",
    "            for i in range(2, len(player1)):\n",
    "                if player1[i - 1] == 10 or player1[i - 2] == 10:\n",
    "                    p1 = p1 + (2 * player1[i])\n",
    "                else:\n",
    "                    p1 = p1 + player1[i]\n",
    "        else:\n",
    "            p1 = player1[0]\n",
    "        if len(player2) > 1:\n",
    "            if player2[0] == 10:\n",
    "                p2 = 10 + (2 * player2[1])\n",
    "            else:\n",
    "                p2 = player2[0] + player2[1]\n",
    "            for i in range(2, len(player2)):\n",
    "                if player2[i - 1] == 10 or player2[i - 2] == 10:\n",
    "                    p2 = p2 + (2 * player2[i])\n",
    "                else:\n",
    "                    p2 = p2 + player2[i]\n",
    "        else:\n",
    "            p2 = player2[0]\n",
    "        if p1 > p2:\n",
    "            return 1\n",
    "        if p1 < p2:\n",
    "            return 2\n",
    "        return 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        if len(player1) == 1 or len(player2) ==1 :\n",
    "            if player1[0] > player2[0] :\n",
    "                return 1\n",
    "            elif player1[0] ==player2[0] :\n",
    "                return 0\n",
    "            else:\n",
    "                return 2\n",
    "            \n",
    "        if len(player1) > 1 or len(player2) >1:\n",
    "            sum1 = 0\n",
    "            sum2 = 0\n",
    "            for i in range(0,len(player1)):\n",
    "                if player1[i-1] == 10 and i-1 >= 0 :\n",
    "                    sum1 += player1[i]*2\n",
    "                elif player1[i-2] == 10 and i-2 >= 0 :\n",
    "                    sum1 += player1[i]*2\n",
    "                else:\n",
    "                    sum1+=player1[i]\n",
    "\n",
    "                if player2[i-1] == 10 and i-1 >= 0 :\n",
    "                    sum2 += player2[i]*2\n",
    "                elif player2[i-2] == 10 and i-2 >= 0 :\n",
    "                    sum2 += player2[i]*2\n",
    "                else:\n",
    "                    sum2+=player2[i]\n",
    "            if sum1 > sum2:\n",
    "                return 1\n",
    "            elif sum1 <sum2:\n",
    "                return 2\n",
    "            else:\n",
    "                return 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        \n",
    "        def calc(nums:list[int]):\n",
    "            n = len(nums)\n",
    "            ans = 0\n",
    "            for i,x in enumerate(nums):\n",
    "                if i >0 and nums[i-1]==10  or i>1 and nums[i-2]==10:\n",
    "                    ans +=  2 * x\n",
    "                else :\n",
    "                    ans +=x\n",
    "            return ans\n",
    "\n",
    "        s1,s2 =calc(player1),calc(player2)\n",
    "        if s1==s2 :return 0\n",
    "        return  1 if s1 >s2 else 2  \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        n = len(player1)\n",
    "        def go(a):\n",
    "            ret = 0\n",
    "            for i in range(n):\n",
    "                if (i > 0 and a[i - 1] == 10) or (i > 1 and a[i - 2] == 10):\n",
    "                    ret += a[i] << 1\n",
    "                else:\n",
    "                    ret += a[i]\n",
    "            return ret\n",
    "        a = go(player1)\n",
    "        b = go(player2)\n",
    "        if a == b:\n",
    "            return 0\n",
    "        if a > b:\n",
    "            return 1\n",
    "        return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def total(player: List[int]) -> int:\n",
    "            prev1 = 0\n",
    "            prev2 = 0\n",
    "            res = prev1 + prev2\n",
    "            for i in range(len(player)):\n",
    "                if prev1 == 10 or prev2 == 10:\n",
    "                    res += player[i] * 2\n",
    "                else:\n",
    "                    res += player[i]\n",
    "                prev1 = prev2\n",
    "                prev2 = player[i]\n",
    "            return res\n",
    "        \n",
    "        s1 = total(player1)\n",
    "        s2 = total(player2)\n",
    "        if s1 > s2:\n",
    "            return 1\n",
    "        elif s1 < s2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        fen1,b1,fen2,b2=0,0,0,0\n",
    "        n=len(player2)\n",
    "        for i in range(n):\n",
    "            if player1[i]==10 and b1==0:\n",
    "                b1=2\n",
    "                fen1+=10\n",
    "            elif player1[i]==10 and b1!=0:\n",
    "                b1=2\n",
    "                fen1+=20\n",
    "            else:\n",
    "                if b1!=0:\n",
    "                    fen1+=player1[i]*2\n",
    "                    b1-=1\n",
    "                else:\n",
    "                    fen1+=player1[i]\n",
    "        for j in range(n):\n",
    "            if player2[j]==10 and b2==0:\n",
    "                b2=2\n",
    "                fen2+=10\n",
    "            elif player2[j]==10 and b2!=0:\n",
    "                b2=2\n",
    "                fen2+=20\n",
    "            else:\n",
    "                if b2!=0:\n",
    "                    fen2+=player2[j]*2\n",
    "                    b2-=1\n",
    "                else:\n",
    "                    fen2+=player2[j]\n",
    "        if fen1>fen2:\n",
    "            return 1\n",
    "        elif fen1==fen2:\n",
    "            return 0\n",
    "        else:\n",
    "            return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        p1,p2 = 0,0\n",
    "        j1,j2 = 1,1\n",
    "        k1,k2 = 0,0\n",
    "        for i in range(len(player1)):\n",
    "            k1 -= 1\n",
    "            k2 -= 1\n",
    "            if k1 < 0:\n",
    "                j1 = 1\n",
    "            if k2 < 0:\n",
    "                j2 = 1    \n",
    "            p1 += j1 * player1[i]\n",
    "            p2 += j2 * player2[i]\n",
    "            if player1[i] == 10:\n",
    "                j1 = 2\n",
    "                k1 = 2\n",
    "            if player2[i] == 10:\n",
    "                j2 = 2\n",
    "                k2 = 2\n",
    "        if p1 > p2:\n",
    "            return 1\n",
    "        elif p2 > p1:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, p1: List[int], p2: List[int]) -> int:\n",
    "        n=len(p1)\n",
    "        if n==1:\n",
    "            a1=p1[0]\n",
    "            a2=p2[0]\n",
    "            if a1==a2:\n",
    "                return 0\n",
    "            if a1>a2:\n",
    "                return 1\n",
    "            else:\n",
    "                return 2\n",
    "        else:\n",
    "            a1=p1[0]\n",
    "            if p1[0]==10:\n",
    "                a1+=2*p1[1]\n",
    "            else:\n",
    "                a1+=p1[1]\n",
    "            for i in range(2,n):\n",
    "                if p1[i-1]==10 or p1[i-2]==10:\n",
    "                    a1+=2*p1[i]\n",
    "                else:\n",
    "                    a1+=p1[i]\n",
    "            a2=p2[0]\n",
    "            if p2[0]==10:\n",
    "                a2+=2*p2[1]\n",
    "            else:\n",
    "                a2+=p2[1]\n",
    "            for i in range(2,n):\n",
    "                if p2[i-1]==10 or p2[i-2]==10:\n",
    "                    a2+=2*p2[i]\n",
    "                else:\n",
    "                    a2+=p2[i]\n",
    "        if a1==a2:\n",
    "            return 0\n",
    "        if a1>a2:\n",
    "            return 1\n",
    "        else:\n",
    "            return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        s1 = sum(player1)\n",
    "        s2 = sum(player2)\n",
    "        for i in range(1, len(player1)):\n",
    "            if player1[i-1] == 10 or i > 1 and player1[i-2] == 10:\n",
    "                s1 += player1[i]\n",
    "            if player2[i-1] == 10 or i > 1 and player2[i-2] == 10:\n",
    "                s2 += player2[i]\n",
    "\n",
    "        return 1 if s1 > s2 else 2 if s2 > s1 else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def help(self, player):\n",
    "        res = 0\n",
    "        for i in range(len(player)):\n",
    "            if i >= 1 and player[i-1] == 10:\n",
    "                res += (2 * player[i])\n",
    "            elif i >= 2 and player[i-2] == 10:\n",
    "                res += (2 * player[i])\n",
    "            else:\n",
    "                res += player[i]\n",
    "        return res\n",
    "\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        if self.help(player1) > self.help(player2):\n",
    "            return 1\n",
    "        elif self.help(player1) < self.help(player2):\n",
    "            return 2\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        total1 = self.calculate(player1)\n",
    "        total2 = self.calculate(player2)\n",
    "        if total1 > total2:\n",
    "            return 1\n",
    "        elif total1 < total2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0\n",
    "\n",
    "\n",
    "    def calculate(self, scores):\n",
    "        total = 0\n",
    "        needDouble = 0\n",
    "        for i, s in enumerate(scores):\n",
    "            if i >= 1 and scores[i-1] == 10:\n",
    "                needDouble = 2\n",
    "            cur = s\n",
    "            if needDouble > 0:\n",
    "                cur *= 2\n",
    "            total += cur\n",
    "            needDouble -= 1\n",
    "        return total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        sp1,sp2 = scorePlayer(player1),scorePlayer(player2)\n",
    "        return 1 if sp1>sp2  else 2 if sp1<sp2 else 0\n",
    "\n",
    "def scorePlayer(a: List[int]) :\n",
    "    ans = 0\n",
    "    for i,x in enumerate(a):\n",
    "        if i and a[i-1] == 10 or i > 1 and a[i-2] == 10:\n",
    "            x = x*2\n",
    "        ans += x\n",
    "    return ans \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# @Author: fankang\n",
    "# @Time: 2023/11/15 18:48\n",
    "class Solution:\n",
    "    def isWinner(self, player1: list[int], player2: list[int]) -> int:\n",
    "        score1 = 0\n",
    "        score2 = 0\n",
    "        len_p = len(player1)\n",
    "        for i in range(len_p):\n",
    "            if i == 0:\n",
    "                score1 += player1[i]\n",
    "                score2 += player2[i]\n",
    "            if i == 1 :\n",
    "                if player1[0] == 10:\n",
    "                    score1 += 2 * player1[i]\n",
    "                else:\n",
    "                    score1 += player1[i]\n",
    "                if player2[0] == 10:\n",
    "                    score2 += 2 * player2[i]\n",
    "                else:\n",
    "                    score2 += player2[i]\n",
    "            if i > 1:\n",
    "                if player1[i - 1] == 10 or player1[i - 2] == 10:\n",
    "                    score1 += 2 * player1[i]\n",
    "                else:\n",
    "                    score1 += player1[i]\n",
    "                if player2[i - 1] == 10 or player2[i - 2] == 10:\n",
    "                    score2 += 2 * player2[i]\n",
    "                else:\n",
    "                    score2 += player2[i]\n",
    "\n",
    "        if score1 > score2:\n",
    "            return 1\n",
    "        elif score1 == score2:\n",
    "            return 0\n",
    "        else:\n",
    "            return 2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        bonus1 = bonus2 = 1\n",
    "        goal1 = goal2 = 0\n",
    "        n = len(player1)\n",
    "        if n > 1:\n",
    "            if player1[0] == 10:\n",
    "                goal1 = player1[0] + 2 * player1[1]\n",
    "            else: goal1 = player1[0] + player1[1]\n",
    "            if player2[0] == 10:\n",
    "                goal2 = player2[0] + 2 * player2[1]\n",
    "            else: goal2 = player2[0] + player2[1]\n",
    "            if n > 2:\n",
    "                for i in range(2, n):\n",
    "                    if player1[i-1] == 10 or player1[i-2] == 10:\n",
    "                        bonus1 = 2\n",
    "                    if player2[i-1] == 10 or player2[i-2] == 10:\n",
    "                        bonus2 = 2\n",
    "                    goal1 += bonus1 * player1[i]\n",
    "                    goal2 += bonus2 * player2[i]\n",
    "                    bonus1 = bonus2 = 1\n",
    "                \n",
    "        else:\n",
    "            for i in range(n):\n",
    "                goal1 += player1[i]\n",
    "                goal2 += player2[i]\n",
    "        \n",
    "        if goal1 > goal2:\n",
    "            return 1\n",
    "        elif goal1 < goal2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def countit(num):\n",
    "            x = num[0]\n",
    "            num = [0] + num\n",
    "            for i in range(2,len(num)):\n",
    "                if num[i-1] == 10 or num[i-2] == 10:\n",
    "                    x += 2*num[i]\n",
    "                else:\n",
    "                    x += num[i]\n",
    "            return x\n",
    "        x1, x2 = countit(player1), countit(player2)\n",
    "        if x1 > x2:\n",
    "            return 1\n",
    "        elif x1 < x2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        player1=[0]*2+player1\n",
    "        player2=[0]*2+player2\n",
    "        n=len(player1)\n",
    "        sum1=sum2=0\n",
    "        for i in range(2,n):\n",
    "            sum1 +=player1[i]*2 if player1[i-1]==10 or player1[i-2]==10 else player1[i]\n",
    "            sum2 +=player2[i]*2 if player2[i-1]==10 or player2[i-2]==10 else player2[i]\n",
    "        return 0 if sum1==sum2 else 1 if sum1>sum2 else 2\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        if len(player1) == 1 or len(player2) ==1 :\n",
    "            if player1[0] > player2[0] :\n",
    "                return 1\n",
    "            elif player1[0] ==player2[0] :\n",
    "                return 0\n",
    "            else:\n",
    "                return 2\n",
    "            \n",
    "        if len(player1) > 1 or len(player2) >1:\n",
    "            sum1 = 0\n",
    "            sum2 = 0\n",
    "            for i in range(0,len(player1)):\n",
    "                if player1[i-1] == 10 and i-1 >= 0 :\n",
    "                    sum1 += player1[i]*2\n",
    "                elif player1[i-2] == 10 and i-2 >= 0 :\n",
    "                    sum1 += player1[i]*2\n",
    "                else:\n",
    "                    sum1+=player1[i]\n",
    "\n",
    "                if player2[i-1] == 10 and i-1 >= 0 :\n",
    "                    sum2 += player2[i]*2\n",
    "                elif player2[i-2] == 10 and i-2 >= 0 :\n",
    "                    sum2 += player2[i]*2\n",
    "                else:\n",
    "                    sum2+=player2[i]\n",
    "            if sum1 > sum2:\n",
    "                return 1\n",
    "            elif sum1 <sum2:\n",
    "                return 2\n",
    "            else:\n",
    "                return 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def who_win(num1:int, num2:int) -> int:\n",
    "    return 1 if num1 > num2 else 2 if num1 < num2 else 0\n",
    "    \n",
    "def get_num(nums):\n",
    "    res = 0\n",
    "    for i, x in enumerate(nums):\n",
    "        if i and nums[i - 1] == 10 or i>1 and nums[i - 2] == 10:\n",
    "            x *= 2\n",
    "        res += x\n",
    "    return res\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        return who_win(get_num(player1), get_num(player2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        score = tag = 0\n",
    "        for x in player1:\n",
    "            if tag > 0:\n",
    "                score += x * 2\n",
    "            else:\n",
    "                score += x\n",
    "            if x == 10:\n",
    "                tag = 2\n",
    "            else:\n",
    "                tag -= 1\n",
    "        tag = 0\n",
    "        for x in player2:\n",
    "            if tag > 0:\n",
    "                score -= x * 2\n",
    "            else:\n",
    "                score -= x\n",
    "            if x == 10:\n",
    "                tag = 2\n",
    "            else:\n",
    "                tag -= 1\n",
    "        return 0 if score == 0 else 1 if score > 0 else 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        p1 = self.calcMark(player1)\n",
    "        p2 = self.calcMark(player2)\n",
    "        if p1 > p2:\n",
    "            return 1\n",
    "        elif p1 < p2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0\n",
    "\n",
    "    def calcMark(self, player):\n",
    "        total_mark = 0\n",
    "        dbl = 0\n",
    "        for mark in player:\n",
    "            if dbl > 0:\n",
    "                total_mark += mark * 2\n",
    "                dbl -= 1\n",
    "            else:\n",
    "                total_mark += mark\n",
    "            if mark == 10:\n",
    "                dbl = 2\n",
    "        return total_mark\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def score(s : List[int]) -> int:\n",
    "            res = 0\n",
    "            for i in range(len(s)):\n",
    "                if i > 0 and s[i - 1] == 10 or i > 1 and s[i - 2] == 10:\n",
    "                    res += s[i]*2\n",
    "                else:\n",
    "                    res += s[i]\n",
    "            return res\n",
    "        s1 = score(player1)\n",
    "        s2 = score(player2)\n",
    "        if s1 > s2:\n",
    "            return 1\n",
    "        elif s2 > s1:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0\n",
    "            \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def calScore(arr):\n",
    "            res = 0\n",
    "            for i in range(len(arr)):\n",
    "                if i>=1 and arr[i-1]==10 or i>=2 and arr[i-2]==10:\n",
    "                    res += arr[i]*2\n",
    "                else:\n",
    "                    res += arr[i]\n",
    "            return res\n",
    "        s1, s2 = calScore(player1), calScore(player2)\n",
    "        if s1 > s2:\n",
    "            return 1\n",
    "        elif s1 < s2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def counts(nums):\n",
    "            ans = nums[0]\n",
    "            for i in range(1,len(nums)):\n",
    "                if i == 1:\n",
    "                    if nums[i-1] == 10:\n",
    "                        ans += 2 * nums[i]\n",
    "                    else:\n",
    "                        ans += nums[i]\n",
    "                else:\n",
    "                    if nums[i-1] == 10 or nums[i-2] == 10:\n",
    "                        ans += 2 * nums[i]\n",
    "                    else:\n",
    "                        ans += nums[i]\n",
    "            return ans\n",
    "        \n",
    "        n1,n2 = counts(player1),counts(player2)\n",
    "        if n1 > n2:\n",
    "            return 1\n",
    "        elif n1 < n2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner_how2(self, player_list):\n",
    "        res = 0\n",
    "        k = 0 # 用一个标记向后两个都是两倍\n",
    "        for i in range(len(player_list)):\n",
    "            if k:\n",
    "                k -= 1\n",
    "                res += 2 * player_list[i]\n",
    "            else:\n",
    "                res += player_list[i]\n",
    "            if player_list[i] == 10:\n",
    "                k = 2\n",
    "        return res\n",
    "    \n",
    "\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        so1 = self.isWinner_how2(player1)\n",
    "        so2 = self.isWinner_how2(player2)\n",
    "        if so1 > so2:\n",
    "            return 1\n",
    "        elif so1 < so2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        if len(player1) > 1:\n",
    "            if player1[0] == 10:\n",
    "                p1 = 10 + (2 * player1[1])\n",
    "            else:\n",
    "                p1 = player1[0] + player1[1]\n",
    "            for i in range(2, len(player1)):\n",
    "                if player1[i - 1] == 10 or player1[i - 2] == 10:\n",
    "                    p1 = p1 + (2 * player1[i])\n",
    "                else:\n",
    "                    p1 = p1 + player1[i]\n",
    "        else:\n",
    "            p1 = player1[0]\n",
    "        if len(player2) > 1:\n",
    "            if player2[0] == 10:\n",
    "                p2 = 10 + (2 * player2[1])\n",
    "            else:\n",
    "                p2 = player2[0] + player2[1]\n",
    "            for i in range(2, len(player2)):\n",
    "                if player2[i - 1] == 10 or player2[i - 2] == 10:\n",
    "                    p2 = p2 + (2 * player2[i])\n",
    "                else:\n",
    "                    p2 = p2 + player2[i]\n",
    "        else:\n",
    "            p2 = player2[0]\n",
    "        if p1 > p2:\n",
    "            return 1\n",
    "        if p1 < p2:\n",
    "            return 2\n",
    "        return 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner_how(self, player_list):\n",
    "        res = 0\n",
    "        for i in range(len(player_list)):\n",
    "            if i - 1 >= 0:\n",
    "                if player_list[i - 1] == 10:\n",
    "                    res += 2 * player_list[i]\n",
    "                else:\n",
    "                    if i - 2 >= 0:\n",
    "                        if player_list[i - 2] == 10:\n",
    "                            res += 2 * player_list[i]\n",
    "                        else:\n",
    "                            res += player_list[i]\n",
    "                    else:\n",
    "                        res += player_list[i]\n",
    "            else:\n",
    "                res += player_list[i]\n",
    "        return res\n",
    "    \n",
    "\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        so1 = self.isWinner_how(player1)\n",
    "        so2 = self.isWinner_how(player2)\n",
    "        if so1 > so2:\n",
    "            return 1\n",
    "        elif so1 < so2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def calculateScore(player: list) ->int:\n",
    "            ans = 0\n",
    "            for index,score in enumerate(player):\n",
    "                if index == 0:\n",
    "                    ans += score\n",
    "                elif index == 1:\n",
    "                    if player[0] == 10:\n",
    "                        ans += 2 * score\n",
    "                    else:\n",
    "                        ans += score\n",
    "                else:\n",
    "                    if player[index - 2] == 10 or player[index - 1] == 10:\n",
    "                        ans += 2 * score\n",
    "                    else:\n",
    "                        ans += score\n",
    "            return ans\n",
    "        p1 = calculateScore(player1)\n",
    "        p2 = calculateScore(player2)\n",
    "        if p1 == p2:\n",
    "            return 0\n",
    "        elif p1 > p2:\n",
    "            return 1\n",
    "        else:\n",
    "            return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "\n",
    "        def count(player: List[int]) -> int:\n",
    "            n = len(player)\n",
    "            ans = player[0]\n",
    "            if n == 1:\n",
    "                return player[0]\n",
    "    \n",
    "            \n",
    "            if player[0] == 10:\n",
    "                ans += player[1] * 2\n",
    "            else:\n",
    "                ans += player[1] \n",
    "\n",
    "            for i in range(2,n):\n",
    "                if player[i-1] == 10 or player[i-2] == 10:\n",
    "                    ans += player[i] * 2\n",
    "                else:\n",
    "                    ans += player[i]\n",
    "            return ans\n",
    "\n",
    "        if count(player1) > count(player2):\n",
    "            return 1\n",
    "        elif count(player1) < count(player2):\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "\n",
    "        def count(player: List[int]) -> int:\n",
    "            n = len(player)\n",
    "            ans = player[0]\n",
    "            if n == 1:\n",
    "                return player[0]\n",
    "    \n",
    "            \n",
    "            if player[0] == 10:\n",
    "                ans += player[1] * 2\n",
    "            else:\n",
    "                ans += player[1] \n",
    "\n",
    "            for i in range(2,n):\n",
    "                if player[i-1] == 10 or player[i-2] == 10:\n",
    "                    ans += player[i] * 2\n",
    "                else:\n",
    "                    ans += player[i]\n",
    "            return ans\n",
    "\n",
    "        if count(player1) > count(player2):\n",
    "            return 1\n",
    "        elif count(player1) < count(player2):\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        s1 = 0\n",
    "        s2 = 0\n",
    "        for i in range(len(player1)):\n",
    "            if i == 0:\n",
    "                s1 += player1[i]\n",
    "                s2 += player2[i]\n",
    "            elif i == 1:\n",
    "                s1 += player1[i] * 2 if player1[i - 1] == 10 else player1[i]\n",
    "                s2 += player2[i] * 2 if player2[i - 1] == 10 else player2[i]\n",
    "            else:\n",
    "                s1 += player1[i] * 2 if player1[i - 2] == 10 or player1[i - 1] == 10 else player1[i]\n",
    "                s2 += player2[i] * 2 if player2[i - 2] == 10 or player2[i - 1] == 10 else player2[i]\n",
    "        return 0 if s1 == s2 else 1 if s1 > s2 else 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# @Author: fankang\n",
    "# @Time: 2023/11/15 18:48\n",
    "class Solution:\n",
    "    def isWinner(self, player1: list[int], player2: list[int]) -> int:\n",
    "        score1 = 0\n",
    "        score2 = 0\n",
    "        len_p = len(player1)\n",
    "        for i in range(len_p):\n",
    "            if i == 0:\n",
    "                score1 += player1[i]\n",
    "                score2 += player2[i]\n",
    "            if i == 1 :\n",
    "                if player1[0] == 10:\n",
    "                    score1 += 2 * player1[i]\n",
    "                if player2[0] == 10:\n",
    "                    score2 += 2 * player2[i]\n",
    "                if player1[0] != 10:\n",
    "                    score1 += player1[i]\n",
    "                if player2[0] != 10:\n",
    "                    score2 += player2[i]\n",
    "            if i > 1:\n",
    "                if player1[i - 1] == 10 or player1[i - 2] == 10:\n",
    "                    score1 += 2 * player1[i]\n",
    "                else:\n",
    "                    score1 += player1[i]\n",
    "                if player2[i - 1] == 10 or player2[i - 2] == 10:\n",
    "                    score2 += 2 * player2[i]\n",
    "                else:\n",
    "                    score2 += player2[i]\n",
    "\n",
    "        if score1 > score2:\n",
    "            return 1\n",
    "        elif score1 == score2:\n",
    "            return 0\n",
    "        else:\n",
    "            return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def score(player):\n",
    "            res = 0\n",
    "            for i, x in enumerate(player):\n",
    "                if i > 0 and player[i - 1] == 10 or i > 1 and player[i - 2] == 10:\n",
    "                    res += 2 * x\n",
    "                else:\n",
    "                    res += x\n",
    "            return res\n",
    "        \n",
    "        s1, s2 = score(player1), score(player2)\n",
    "        return 0 if s1 == s2 else 1 if s1 > s2 else 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def total(player: List[int]) -> int:\n",
    "            prev1 = 0\n",
    "            prev2 = 0\n",
    "            res = prev1 + prev2\n",
    "            for i in range(len(player)):\n",
    "                res += player[i]\n",
    "                if prev1 == 10 or prev2 == 10:\n",
    "                    res += player[i]\n",
    "                prev1 = prev2\n",
    "                prev2 = player[i]\n",
    "            return res\n",
    "        s1 = total(player1)\n",
    "        s2 = total(player2)\n",
    "        if s1 > s2:\n",
    "            return 1\n",
    "        elif s1 < s2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def score(a: List[int]) -> int:\n",
    "            res = 0\n",
    "            for i, x in enumerate(a):\n",
    "                if i and a[i - 1] == 10 or i > 1 and a[i - 2] == 10:\n",
    "                    x *= 2\n",
    "                res += x\n",
    "            return res\n",
    "        s1, s2 = score(player1), score(player2)\n",
    "        return 1 if s1 > s2 else 2 if s1 < s2 else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def score(lst):\n",
    "            lst = [0, 0] + lst\n",
    "            return sum(lst[i] << (1 if lst[i - 1] == 10 or lst[i - 2] == 10 else 0) for i in range(2, len(lst)))\n",
    "        s1, s2 = score(player1), score(player2)\n",
    "        return 1 if s1 > s2 else 2 if s1 < s2 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "#         ans = [0, 0]\n",
    "#         n = len(player1)\n",
    "#         full_beat_2 = False\n",
    "#         full_beat_1 = False\n",
    "#         for i in range(n):\n",
    "#             if full_beat_1:\n",
    "#                 ans[0] += 2 * player1[i]\n",
    "#             else:\n",
    "#                 ans[0] += player1[i]\n",
    "\n",
    "#             if full_beat_2:\n",
    "#                 ans[1] += 2 * player2[i]\n",
    "#             else:\n",
    "#                 ans[1] += player2[i]\n",
    "            \n",
    "#             if player1[i] == 10 and i < 2:\n",
    "#                 full_beat_1 = True\n",
    "#             if player2[i] == 10 and i < 2:\n",
    "#                 full_beat_2 = True\n",
    "\n",
    "#         if ans[0] > ans[1]:\n",
    "#             return 1\n",
    "#         elif ans[0] == ans[1]:\n",
    "#             return 0\n",
    "#         else:\n",
    "#             return 2\n",
    "def score(a: List[int]) -> int:\n",
    "    res = 0\n",
    "    for i, x in enumerate(a):\n",
    "        if i and a[i - 1] == 10 or i > 1 and a[i - 2] == 10:\n",
    "            x *= 2\n",
    "        res += x\n",
    "    return res\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        s1, s2 = score(player1), score(player2)\n",
    "        return 1 if s1 > s2 else 2 if s1 < s2 else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def cal(arr):\n",
    "            prev10 = -inf\n",
    "            ans = 0\n",
    "            for i, x in enumerate(arr):\n",
    "                ans += 2 ** (i - prev10 <= 2) * x\n",
    "                if x == 10: prev10 = i\n",
    "            return ans\n",
    "        \n",
    "        s1, s2 = cal(player1), cal(player2)\n",
    "        return 1 if s1 > s2 else 2 if s1 < s2 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def compute(a: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for i, x in enumerate(a):\n",
    "            if i and a[i - 1] == 10 or i > 1 and a[i - 2] == 10:\n",
    "                x *= 2\n",
    "            ans += x\n",
    "        return ans\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        s1, s2 = compute(player1), compute(player2)\n",
    "        return 1 if s1 > s2 else 2 if s1 < s2 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        # 一个函数计算分数\n",
    "        def calculate(player, score = 0):\n",
    "            for i in range(len(player)):    \n",
    "                #遍历循环一下\n",
    "                if i == 1 and player[i-1] == 10:    \n",
    "                    #特殊情况第一个是10\n",
    "                    score += 2 * player[i]\n",
    "                elif i-2 >= 0 and 10 in player[i - 2:i]:    \n",
    "                    #前两个数字中有一个10\n",
    "                    score += 2 * player[i]\n",
    "                else:\n",
    "                    #没有10\n",
    "                    score += player[i]\n",
    "            return score\n",
    "\n",
    "        # 比较两位选手分数\n",
    "        if calculate(player1) > calculate(player2):\n",
    "            return 1\n",
    "        elif calculate(player1) == calculate(player2):\n",
    "            return 0\n",
    "        else:\n",
    "            return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        player1=[0]*2+player1\n",
    "        player2=[0]*2+player2\n",
    "        n=len(player1)\n",
    "        sum1=sum2=0\n",
    "        for i in range(2,n):\n",
    "            sum1 +=player1[i]*2 if player1[i-1]==10 or player1[i-2]==10 else player1[i]\n",
    "            sum2 +=player2[i]*2 if player2[i-1]==10 or player2[i-2]==10 else player2[i]\n",
    "        if sum1>sum2:\n",
    "            return 1\n",
    "        elif sum1<sum2:\n",
    "            return 2\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# @Author: fankang\n",
    "# @Time: 2023/11/15 18:48\n",
    "class Solution:\n",
    "    def isWinner(self, player1: list[int], player2: list[int]) -> int:\n",
    "        score1 = 0\n",
    "        score2 = 0\n",
    "        len_p = len(player1)\n",
    "        for i in range(len_p):\n",
    "            if i == 0:\n",
    "                score1 += player1[i]\n",
    "            if i == 1 and player1[0] == 10:\n",
    "                score1 += 2 * player1[i]\n",
    "            elif i == 1 and player1[0] != 10:\n",
    "                score1 += player1[i]\n",
    "            if i > 1:\n",
    "                if player1[i - 1] == 10 or player1[i - 2] == 10:\n",
    "                    score1 += 2 * player1[i]\n",
    "                else:\n",
    "                    score1 += player1[i]\n",
    "\n",
    "        for i in range(len_p):\n",
    "            if i == 0:\n",
    "                score2 += player2[i]\n",
    "            if i == 1 and player2[0] == 10:\n",
    "                score2 += 2 * player2[i]\n",
    "            elif i == 1 and player2[0] != 10:\n",
    "                score2 += player2[i]\n",
    "            if i > 1:\n",
    "                if player2[i - 1] == 10 or player2[i - 2] == 10:\n",
    "                    score2 += 2 * player2[i]\n",
    "                else:\n",
    "                    score2 += player2[i]\n",
    "\n",
    "        if score1 > score2:\n",
    "            return 1\n",
    "        elif score1 == score2:\n",
    "            return 0\n",
    "        else:\n",
    "            return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        if len(player1)==1:\n",
    "            if player1[0]>player2[0]:\n",
    "                return 1\n",
    "            elif player1[0]<player2[0]:\n",
    "                return 2\n",
    "            else: return 0\n",
    "        sum1=0\n",
    "        for i in range(1,len(player1)):\n",
    "            if i==1:\n",
    "                if player1[i-1]==10:\n",
    "                    sum1+=player1[i]\n",
    "            else:\n",
    "                if player1[i-2]==10 or player1[i-1]==10:\n",
    "                    sum1+=player1[i]\n",
    "        sum2=0\n",
    "        for i in range(1,len(player2)):\n",
    "            if i==1:\n",
    "                if player2[i-1]==10:\n",
    "                    sum2+=player2[i]\n",
    "            else:\n",
    "                if player2[i-2]==10 or player2[i-1]==10:\n",
    "                    sum2+=player2[i]    \n",
    "        sum1+=sum(player1)\n",
    "        sum2+=sum(player2)\n",
    "        if sum1>sum2:\n",
    "            return 1\n",
    "        elif sum1<sum2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        k1 = cnt1 = 0\n",
    "        for i in range(len(player1)):\n",
    "            k1 += player1[i]\n",
    "            if i >= 1:\n",
    "                if i == 1:\n",
    "                    if player1[i-1] == 10:\n",
    "                        k1 += player1[i]\n",
    "                else:\n",
    "                    if player1[i-1] == 10 or player1[i-2] == 10:\n",
    "                        k1 += player1[i]\n",
    "        k2 = cnt2 = 0     \n",
    "        for i in range(len(player2)):\n",
    "            k2 += player2[i]\n",
    "            if i >= 1:\n",
    "                if i == 1:\n",
    "                    if player2[i-1] == 10:\n",
    "                        k2 += player2[i]\n",
    "                else:\n",
    "                    if player2[i-1] == 10 or player2[i-2] == 10:\n",
    "                        k2 += player2[i]\n",
    "        print(k1, \" \", k2)\n",
    "        if k1 >= k2:\n",
    "            return 1 if k1 > k2 else 0\n",
    "        else: return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def SUM(x):\n",
    "            ans=sum(x)\n",
    "            s=set()\n",
    "            for i,j in enumerate(x):\n",
    "                if j==10:\n",
    "                    s.add(i+1)\n",
    "                    s.add(i+2)\n",
    "            for i in s:\n",
    "                if i<len(x):\n",
    "                    ans+=x[i]\n",
    "            return ans\n",
    "        if SUM(player1)>SUM(player2):\n",
    "            return 1\n",
    "        elif SUM(player1)<SUM(player2):\n",
    "            return 2\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        value1,value2 = 0,0\n",
    "        flag = 2\n",
    "        for i in player1:\n",
    "            if flag < 2:\n",
    "                value1 += i*2\n",
    "            else:\n",
    "                value1 += i\n",
    "            if i == 10:\n",
    "                flag = 0\n",
    "            elif flag < 2:\n",
    "                flag += 1\n",
    "        flag = 2\n",
    "        for j in player2:\n",
    "            if flag < 2:\n",
    "                value2 += j*2\n",
    "            else:\n",
    "                value2 += j\n",
    "            if j == 10:\n",
    "                flag = 0\n",
    "            elif flag < 2:\n",
    "                flag += 1\n",
    "        \n",
    "        if value1 > value2:\n",
    "            return 1\n",
    "        if value1 < value2:\n",
    "            return 2\n",
    "        return 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        ans = player1[0]\n",
    "        res = player2[0]\n",
    "        for  i in range(1,len(player1)):\n",
    "            if i-2>-1:\n",
    "                if player1[i-1]==10 or player1[i-2] == 10:\n",
    "                    ans += 2*player1[i]\n",
    "                else:\n",
    "                    ans += player1[i]\n",
    "            else:\n",
    "                if player1[i-1] ==10:\n",
    "                    ans +=player1[i]*2\n",
    "                else:\n",
    "                    ans +=player1[i]\n",
    "        \n",
    "        for  i in range(1,len(player2)):\n",
    "            if i-2>-1:\n",
    "                if player2[i-1]==10 or player2[i-2] == 10:\n",
    "                    res += 2*player2[i]\n",
    "                else:\n",
    "                    res += player2[i]\n",
    "            else:\n",
    "                if player2[i-1] ==10:\n",
    "                    res +=player2[i]*2\n",
    "                else:\n",
    "                    res +=player2[i]\n",
    "        if ans>res:\n",
    "            return 1\n",
    "        if ans<res:\n",
    "            return 2\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        sum1=0\n",
    "        sum2=0\n",
    "        for i in range(len(player1)):\n",
    "            if i ==0:\n",
    "                sum1+=player1[i]\n",
    "            if i==1:\n",
    "                if player1[i-1]==10:\n",
    "                    sum1+=(2*player1[i])\n",
    "                else:\n",
    "                    sum1+=player1[i]\n",
    "            if i >1:\n",
    "                if player1[i-2]==10 or player1[i-1]==10:\n",
    "                    sum1+=(2*player1[i])\n",
    "                else:\n",
    "                    sum1+=player1[i]\n",
    "        for j in range(len(player2)):\n",
    "            if j ==0:\n",
    "                sum2+=player2[j]\n",
    "            if j==1:\n",
    "                if player2[j-1]==10:\n",
    "                    sum2+=(2*player2[j])\n",
    "                else:\n",
    "                    sum2+=player2[j]\n",
    "            if j >1:\n",
    "                if player2[j-2]==10 or player2[j-1]==10:\n",
    "                    sum2+=(2*player2[j])\n",
    "                else:\n",
    "                    sum2+=player2[j]\n",
    "        if sum1>sum2:\n",
    "            return 1\n",
    "        if sum1<sum2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        n = len(player1)\n",
    "        s1, s2 = sum(player1), sum(player2)\n",
    "        lst1, lst2 = set(), set()\n",
    "        for i in range(n):\n",
    "            if player1[i] == 10:\n",
    "                lst1.add(i + 1)\n",
    "                lst1.add(i + 2)\n",
    "            if player2[i] == 10:\n",
    "                lst2.add(i + 1)\n",
    "                lst2.add(i + 2)\n",
    "        for t in lst1:\n",
    "            if t < n:\n",
    "                s1 += player1[t]\n",
    "        for r in lst2:\n",
    "            if r < n:\n",
    "                s2 += player2[r]\n",
    "\n",
    "        if s1 > s2:\n",
    "            return 1\n",
    "        elif s1 < s2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        t1=sum(player1)\n",
    "        for i in range(2,len(player1)):\n",
    "            if player1[i-1]==10 or player1[i-2]==10:\n",
    "                t1+=player1[i]\n",
    "        if player1[0]==10 and 1<len(player1): ###题意理解\n",
    "            t1+=player1[1]\n",
    "        t2=sum(player2)\n",
    "        for i in range(2,len(player2)):\n",
    "            if player2[i-1]==10 or player2[i-2]==10:\n",
    "                t2+=player2[i]\n",
    "        if player2[0]==10 and 1<len(player2): ###题意理解\n",
    "            t2+=player2[1]\n",
    "        if t1>t2:\n",
    "            return 1\n",
    "        elif t1<t2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def sum(nums):\n",
    "            flag = 0\n",
    "            sum = 0\n",
    "            for num in nums:\n",
    "                if flag:\n",
    "                    sum+=num*2\n",
    "                    flag -= 1\n",
    "                else:\n",
    "                    sum+=num       \n",
    "                if num==10:\n",
    "                    flag = 2    \n",
    "            return sum\n",
    "        if sum(player1)>sum(player2):\n",
    "            return 1\n",
    "        if  sum(player1)<sum(player2):\n",
    "            return 2\n",
    "        return 0                       \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def score(player: List[int]) -> int:\n",
    "    flag = 0\n",
    "    sco = 0\n",
    "    for x in player:\n",
    "        if flag > 0:\n",
    "            sco += 2*x\n",
    "            flag -= 1\n",
    "        else:\n",
    "            sco += x\n",
    "        if x == 10:\n",
    "            flag = 2\n",
    "    return sco\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        p1 = score(player1)\n",
    "        p2 = score(player2)\n",
    "        if p1 > p2: return 1\n",
    "        if p1 < p2: return 2\n",
    "        return 0\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def func(player1,player2):\n",
    "            n = len(player1)\n",
    "\n",
    "            count1 = player1[0]\n",
    "            count2 = player2[0]\n",
    "            if n==1:\n",
    "                pass\n",
    "            elif n==2:\n",
    "                count1 += player1[1] * (2 if player1[0]==10 else 1)\n",
    "                count2 += player2[1] * (2 if player2[0]==10 else 1)\n",
    "            else:\n",
    "                count1 += player1[1] * (2 if player1[0]==10 else 1)\n",
    "                count2 += player2[1] * (2 if player2[0]==10 else 1)\n",
    "                for i in range(2,n):\n",
    "                    if player1[i-2]==10 or player1[i-1]==10:\n",
    "                        count1+= 2*player1[i]\n",
    "                    else:\n",
    "                        count1+=player1[i]\n",
    "\n",
    "                for i in range(2,n):\n",
    "                    if player2[i-2]==10 or player2[i-1]==10:\n",
    "                        count2+= 2*player2[i]\n",
    "                    else:\n",
    "                        count2+=player2[i]\n",
    "\n",
    "            if count1>count2:\n",
    "                return 1\n",
    "            elif count1<count2:\n",
    "                return 2\n",
    "            else:\n",
    "                return 0\n",
    "            \n",
    "        return func(player1,player2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        n1 = len(player1)\n",
    "        n2 = len(player2)\n",
    "        res1 = 0\n",
    "        res2 = 0\n",
    "        for i in range(n1):\n",
    "            if i > 0 and player1[i - 1] == 10 or i > 1 and player1[i - 2] == 10:\n",
    "                res1 += 2 * player1[i]\n",
    "            else:\n",
    "                res1 += player1[i]\n",
    "        \n",
    "        for i in range(n2):\n",
    "            if i > 0 and player2[i - 1] == 10 or i > 1 and player2[i - 2] == 10:\n",
    "                res2 += 2 * player2[i]\n",
    "            else:\n",
    "                res2 += player2[i]\n",
    "        if res1 > res2:\n",
    "            return 1\n",
    "        elif res1 < res2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0\n",
    "                \n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "def score(a: List[int]) -> int:\n",
    "    res = 0\n",
    "    for i, x in enumerate(a):\n",
    "        if i and a[i - 1] == 10 or i > 1 and a[i - 2] == 10:\n",
    "            x *= 2\n",
    "        res += x\n",
    "    return res\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        s1, s2 = score(player1), score(player2)\n",
    "        return 1 if s1 > s2 else 2 if s1 < s2 else 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        n = len(player1) + 1\n",
    "        player1 = [0] + player1\n",
    "        player2 = [0] + player2\n",
    "        s1 = sum([2 * player1[i] if i >= 2 and max(player1[i-2:i]) == 10 else player1[i] for i in range(n)])\n",
    "        s2 = sum([2 * player2[i] if i >= 2 and max(player2[i-2:i]) == 10 else player2[i] for i in range(n)])\n",
    "        if s1 == s2:\n",
    "            return 0\n",
    "        if s1 > s2:\n",
    "            return 1\n",
    "        return 2        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def cal(s):\n",
    "            res = s[0]\n",
    "            for i in range(1, len(s)):\n",
    "                res += s[i]\n",
    "                if s[i - 1] == 10 or (i - 2 >= 0 and s[i - 2] == 10):\n",
    "                    res += s[i]\n",
    "            return res\n",
    "        a, b = cal(player1), cal(player2)\n",
    "        if a == b:\n",
    "            return 0\n",
    "        return 1 if a > b else 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        res1=player1[0]\n",
    "        res2=player2[0]\n",
    "        for i in range(1,len(player1)):\n",
    "            if i==1:\n",
    "                res1+=player1[i] if player1[0]<10 else 2*player1[i]\n",
    "                res2+=player2[i] if player2[0]<10 else 2*player2[i]\n",
    "            else:\n",
    "                if player1[i-2]==10 or player1[i-1]==10:\n",
    "                    res1+=2*player1[i]\n",
    "                else:\n",
    "                    res1+=player1[i]\n",
    "                if player2[i-2]==10 or player2[i-1]==10:\n",
    "                    res2+=2*player2[i]\n",
    "                else:\n",
    "                    res2+=player2[i]\n",
    "        if res1<res2:\n",
    "            return 2\n",
    "        elif res1>res2:\n",
    "            return 1\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        n = len(player1)\n",
    "        s1, s2 = player1[0], player2[0]\n",
    "        if n > 1:\n",
    "            if player1[0] == 10:\n",
    "                s1 += player1[1] * 2\n",
    "            else:\n",
    "                s1 += player1[1]\n",
    "        if n > 1:\n",
    "            if player2[0] == 10:\n",
    "                s2 += player2[1] * 2\n",
    "            else:\n",
    "                s2 += player2[1]\n",
    "        for i in range(2, n):\n",
    "            if 10 in player1[i - 2: i]:\n",
    "                s1 += player1[i] * 2\n",
    "            else:\n",
    "                s1 += player1[i]\n",
    "\n",
    "            if 10 in player2[i - 2: i]:\n",
    "                s2 += player2[i] * 2\n",
    "            else:\n",
    "                s2 += player2[i]\n",
    "        if s1 > s2:\n",
    "            return 1\n",
    "        elif s1 < s2:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def score(a: List[int]) -> int:\n",
    "    res = 0\n",
    "    for i, x in enumerate(a):\n",
    "        if i and a[i - 1] == 10 or i > 1 and a[i - 2] == 10:\n",
    "            x *= 2\n",
    "        res += x\n",
    "    return res\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        s1, s2 = score(player1), score(player2)\n",
    "        return 1 if s1 > s2 else 2 if s1 < s2 else 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        value1,value2 = 0,0\n",
    "        flag = 2\n",
    "        for i in player1:\n",
    "            if flag < 2:\n",
    "                value1 += i*2\n",
    "            else:\n",
    "                value1 += i\n",
    "            if i == 10:\n",
    "                flag = 0\n",
    "            elif flag < 2:\n",
    "                flag += 1\n",
    "        flag = 2\n",
    "        for j in player2:\n",
    "            if flag < 2:\n",
    "                value2 += j*2\n",
    "            else:\n",
    "                value2 += j\n",
    "            if j == 10:\n",
    "                flag = 0\n",
    "            elif flag < 2:\n",
    "                flag += 1\n",
    "        \n",
    "        if value1 > value2:\n",
    "            return 1\n",
    "        if value1 < value2:\n",
    "            return 2\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        player1.append(0)\n",
    "        player2.append(0)\n",
    "        d = 0\n",
    "        e = 0\n",
    "        for i in range(len(player1)):\n",
    "            if i > 0 and (int(player1[i-1]) == 10 or int(player1[i-2]) == 10) :\n",
    "                c = 2*int(player1[i])\n",
    "            else:\n",
    "                c = int(player1[i])\n",
    "            d += c\n",
    "        for f in range(len(player2)):\n",
    "            if f > 0 and (int(player2[f-1]) == 10 or int(player2[f - 2]) == 10):\n",
    "                    g = 2 * int(player2[f])\n",
    "            else:\n",
    "                g = int(player2[f])\n",
    "            e += g\n",
    "        if d > e:\n",
    "            return 1\n",
    "        elif d < e:\n",
    "            return 2\n",
    "        else:\n",
    "            return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def score(a : List[int]) -> int:\n",
    "    res = 0 \n",
    "    for i , x in enumerate(a):\n",
    "        if i and a[i-1] == 10 or i >1 and a[i-2] == 10 :\n",
    "            x += x \n",
    "        res += x \n",
    "    return res \n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        s1 , s2 = score(player1) , score(player2)\n",
    "        return 1 if s1 > s2 else 2  if s2 > s1 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        if len(player1) == 1 or len(player2) ==1 :\n",
    "            if player1[0] > player2[0] :\n",
    "                return 1\n",
    "            elif player1[0] ==player2[0] :\n",
    "                return 0\n",
    "            else:\n",
    "                return 2\n",
    "            \n",
    "        if len(player1) > 1 or len(player2) >1:\n",
    "            sum1 = 0\n",
    "            sum2 = 0\n",
    "            for i in range(0,len(player1)):\n",
    "                if player1[i-1] == 10 and i-1 >= 0 :\n",
    "                    sum1 += player1[i]*2\n",
    "                elif player1[i-2] == 10 and i-2 >= 0 :\n",
    "                    sum1 += player1[i]*2\n",
    "                else:\n",
    "                    sum1+=player1[i]\n",
    "\n",
    "                if player2[i-1] == 10 and i-1 >= 0 :\n",
    "                    sum2 += player2[i]*2\n",
    "                elif player2[i-2] == 10 and i-2 >= 0 :\n",
    "                    sum2 += player2[i]*2\n",
    "                else:\n",
    "                    sum2+=player2[i]\n",
    "            if sum1 > sum2:\n",
    "                return 1\n",
    "            elif sum1 <sum2:\n",
    "                return 2\n",
    "            else:\n",
    "                return 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        n = len(player1)\n",
    "        sum1 = 0\n",
    "        sum2 = 0\n",
    "        for i in range(n):\n",
    "            if i >= 2 and (player1[i-1] == 10 or player1[i - 2] == 10):\n",
    "                sum1 += player1[i] * 2\n",
    "            elif 1 <= i < 2 and player1[i-1] == 10:\n",
    "                sum1 += player1[i] * 2\n",
    "            else:\n",
    "                sum1 += player1[i]\n",
    "\n",
    "        for i in range(n):\n",
    "            if i >= 2 and (player2[i-1] == 10 or player2[i - 2] == 10):\n",
    "                sum2 += player2[i] * 2\n",
    "            elif 1 <= i < 2 and player2[i-1] == 10:\n",
    "                sum2 += player2[i] * 2\n",
    "            else:\n",
    "                sum2 += player2[i]\n",
    "        if sum1 > sum2:\n",
    "            return 1\n",
    "        elif sum1 < sum2:\n",
    "            return 2\n",
    "        return 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        p1_count = 0\n",
    "        p2_count = 0\n",
    "        # for p1,p11, p2,p22 in zip(, enumerate(player2[::-1])):\n",
    "        #     print(p1,p11, p2,p22) \n",
    "        for p1, p11 in enumerate(player1[::-1]):\n",
    "            # print(p1,p11)\n",
    "\n",
    "            if len(player1) >= p1+2 and player1[::-1][p1+1] == 10:\n",
    "                p1_count += 2 * p11\n",
    "            elif len(player1) >= p1+3 and player1[::-1][p1+2] == 10:\n",
    "                p1_count += 2 * p11\n",
    "            else:\n",
    "                p1_count += p11\n",
    "        \n",
    "        for p2, p22 in enumerate(player2[::-1]):\n",
    "            # print(p2,p22)\n",
    "            re_p = player2[::-1]\n",
    "            if len(player2) >= p2+2 and re_p[p2+1] == 10:\n",
    "                p2_count += 2 * p22\n",
    "            elif len(player1) >= p2+3 and re_p[p2+2] == 10:\n",
    "                p2_count += 2 * p22\n",
    "            else:\n",
    "                p2_count += p22\n",
    "        \n",
    "        if p1_count > p2_count:\n",
    "            res = 1\n",
    "        elif p1_count < p2_count:\n",
    "            res = 2\n",
    "        else:\n",
    "            res = 0\n",
    "        # print(p1_count, p2_count)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        a, b = 0, 0\n",
    "        for i in range(len(player1)):\n",
    "            if i >= 1 and player1[i - 1] == 10:\n",
    "                a += 2 * player1[i]\n",
    "            elif i >= 2 and player1[i - 2] == 10:\n",
    "                a += 2 * player1[i]\n",
    "            else:\n",
    "                a += player1[i]                \n",
    "        for i in range(len(player2)):\n",
    "            if i >= 1 and player2[i - 1] == 10:\n",
    "                b += 2 * player2[i]\n",
    "            elif i >= 2 and player2[i - 2] == 10:\n",
    "                b += 2 * player2[i]\n",
    "            else:\n",
    "                b += player2[i]\n",
    "        return 1 if a > b else (0 if a == b else 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def compute(a: List[int]) -> int:\n",
    "        ans = 0\n",
    "        for i, x in enumerate(a):\n",
    "            if i and a[i - 1] == 10 or i > 1 and a[i - 2] == 10:\n",
    "                x *= 2\n",
    "            ans += x\n",
    "        return ans\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        s1, s2 = compute(player1), compute(player2)\n",
    "        return 1 if s1 > s2 else 2 if s1 < s2 else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isWinner(self, player1: List[int], player2: List[int]) -> int:\n",
    "        def nums(player):\n",
    "            n=0\n",
    "            if player==None:\n",
    "                return n\n",
    "            for i in range(len(player)):\n",
    "                if i-1>=0:\n",
    "                    if player[i-1]==10: \n",
    "                        n+=player[i]*2\n",
    "                        continue\n",
    "                if i-2>=0:\n",
    "                    if player[i-2]==10: \n",
    "                        n+=player[i]*2\n",
    "                        continue\n",
    "                n+=player[i]\n",
    "            return n\n",
    "        num1,num2=0,0\n",
    "        num1=nums(player1)\n",
    "        num2=nums(player2)\n",
    "        if num1==num2:\n",
    "            return 0\n",
    "        if num1>num2:\n",
    "            return 1\n",
    "        return 2\n",
    "        "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
